<template>
  <transition name="batch-slide">
    <div v-if="count > 0" class="batch-toolbar">
      <el-card shadow="never" class="batch-card">
        <div class="batch-main">
          <div class="batch-info">
            <span class="count">{{ count }}</span>
            <span>项缺陷已选择</span>
          </div>
          <div class="batch-actions">
            <el-dropdown 
              trigger="click" 
              placement="top-start"
              :disabled="loading"
              @command="handleCommand"
            >
              <el-button size="small" type="primary" :loading="loading">
                批量操作
                <el-icon class="el-icon--right"><ArrowDown /></el-icon>
              </el-button>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item command="update-status">
                    <el-icon><DocumentChecked /></el-icon>
                    <span>更新状态</span>
                  </el-dropdown-item>
                  <el-dropdown-item command="update-priority">
                    <el-icon><Sort /></el-icon>
                    <span>更新优先级</span>
                  </el-dropdown-item>
                  <el-dropdown-item command="update-severity">
                    <el-icon><Warning /></el-icon>
                    <span>更新严重程度</span>
                  </el-dropdown-item>
                  <el-dropdown-item command="update-type">
                    <el-icon><CollectionTag /></el-icon>
                    <span>更新缺陷类型</span>
                  </el-dropdown-item>
                  <el-dropdown-item command="update-source">
                    <el-icon><Folder /></el-icon>
                    <span>更新缺陷来源</span>
                  </el-dropdown-item>
                  <el-dropdown-item divided command="assign">
                    <el-icon><User /></el-icon>
                    <span>分配负责人</span>
                  </el-dropdown-item>
                  <el-dropdown-item command="update-reporter">
                    <el-icon><Avatar /></el-icon>
                    <span>更新报告人</span>
                  </el-dropdown-item>
                  <el-dropdown-item command="update-project">
                    <el-icon><FolderOpened /></el-icon>
                    <span>更新所属项目</span>
                  </el-dropdown-item>
                  <el-dropdown-item divided command="remove">
                    <el-icon><Delete /></el-icon>
                    <span style="color: #f56c6c;">批量删除</span>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
            <el-button size="small" text class="clear-btn" :disabled="loading" @click="$emit('clear')">
              取消选择
            </el-button>
          </div>
        </div>
      </el-card>
    </div>
  </transition>
</template>

<script setup lang="ts">
import { ArrowDown, DocumentChecked, Sort, Warning, CollectionTag, Folder, User, Avatar, FolderOpened, Delete } from '@element-plus/icons-vue'

defineProps<{
  count: number
  loading?: boolean
  statusOptions: Array<{ value: string; label: string }>
  priorityOptions: Array<{ value: string; label: string }>
  severityOptions: Array<{ value: string; label: string }>
  typeOptions: Array<{ value: string; label: string }>
  sourceOptions: Array<{ value: string; label: string }>
  users: Array<{ id: string; name: string }>
}>()

const emit = defineEmits<{
  (event: 'update-status'): void
  (event: 'update-priority'): void
  (event: 'update-severity'): void
  (event: 'update-type'): void
  (event: 'update-source'): void
  (event: 'assign'): void
  (event: 'update-reporter'): void
  (event: 'update-project'): void
  (event: 'remove'): void
  (event: 'clear'): void
}>()

const handleCommand = (command: string) => {
  switch (command) {
    case 'update-status':
      emit('update-status')
      break
    case 'update-priority':
      emit('update-priority')
      break
    case 'update-severity':
      emit('update-severity')
      break
    case 'update-type':
      emit('update-type')
      break
    case 'update-source':
      emit('update-source')
      break
    case 'assign':
      emit('assign')
      break
    case 'update-reporter':
      emit('update-reporter')
      break
    case 'update-project':
      emit('update-project')
      break
    case 'remove':
      emit('remove')
      break
    default:
      break
  }
}
</script>

<style scoped lang="scss">
.batch-toolbar {
  position: relative;
  z-index: 10;
  margin: 0;
  flex-shrink: 0;
  width: auto;
  min-width: 0;
  overflow: visible;
}

.batch-card {
  border-radius: 8px;
  border: 1px solid #e4e7ed;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  background: linear-gradient(135deg, rgba(79, 111, 236, 0.1) 0%, rgba(105, 162, 255, 0.1) 100%);
  width: auto;
  min-width: 0;
  
  :deep(.el-card__body) {
    padding: 10px 16px;
    min-width: 0;
    overflow: hidden;
  }
}

.batch-main {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  min-width: 0;
  width: auto;
  flex-wrap: wrap;
}

.batch-info {
  font-weight: 600;
  color: #2c3a5f;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 13px;
  
  .count {
    font-size: 16px;
    color: #409eff;
    font-weight: 700;
  }
  
  > span:not(.count) {
    font-size: 13px;
    color: #606266;
  }
}

.batch-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
  
  :deep(.el-dropdown) {
    .el-button {
      white-space: nowrap;
      flex-shrink: 0;
      min-width: auto;
      padding: 6px 16px;
      font-size: 13px;
      height: 28px;
    }
  }
  
  :deep(.el-button--text) {
    color: #6073a3;
    font-size: 12px;
    padding: 4px 8px;
  }
  
  :deep(.el-dropdown-menu__item) {
    display: flex;
    align-items: center;
    gap: 8px;
    
    .el-icon {
      font-size: 16px;
      color: #606266;
    }
  }
}

.clear-btn {
  font-weight: 500;
  flex-shrink: 0;
}

.batch-slide-enter-active,
.batch-slide-leave-active {
  transition: all 0.25s ease;
}

.batch-slide-enter-from,
.batch-slide-leave-to {
  opacity: 0;
  transform: translateY(-8px);
}
</style>

